home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 543 / text0000.txt < prev   
Encoding:
Text File  |  1996-08-06  |  991 b   |  38 lines

  1. In article <4gognf$et@news.bridge.net>,
  2. David Byrden  <100101.2547@compuserve.com> wrote:
  3. ><<<<<<<
  4. >
  5. >Why is it not allowed to delegate the initialisation to another
  6. >constructor
  7. >
  8. >class X
  9. >{
  10. >public:
  11. >    X (int i) : i_(i) {}
  12. >
  13. >    X () : X(34) {}             // Not allowed
  14. >>>>>>>>>>
  15. >
  16. >
  17. >     Why not use      X (int i = 34 ) : i_(i) {}
  18.  
  19. >[ I think he was concerned with the more general case of a complicated
  20. >  initialization (not assignment) that must be repeated for each
  21. >  constructor. -sdc, moderator
  22. >]
  23.  
  24. Well, one could use a similar thing using a member function:
  25.  
  26. X (int i) { init(i); }
  27. X () { init(34); }
  28.  
  29. where init is a member function for class X.
  30.  
  31. Anders
  32. [ To submit articles: Try just posting with your newsreader.
  33.               If that fails, use mailto:std-c++@ncar.ucar.edu
  34.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  35.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  36.   Comments? mailto:std-c++-request@ncar.ucar.edu
  37. ]
  38.